package cn.zhiquxing.lock.master_worker;

import lombok.Data;

import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;

@Data
public class Task<R> {
    static AtomicInteger index = new AtomicInteger(1);
    //任务的回调函数
    public Consumer<Task<R>> resultAction;
    //任务的id
    private int id;
    
    private int workerId;
    //计算结果
    R result = null;

    public Task() {
        this.id = index.getAndIncrement();
        
    }
    
    public void execute() {
        this.result = this.doExecute();
        resultAction.accept(this);
    }

    protected R doExecute() {
        return null;
    }
    
}
